//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hbase.controller;

import com.sitech.common.utils.StringUtils;
import com.ssm.pojo.User;
import com.ssm.service.UserService;
import com.yhzhou.test.Test1;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

import static com.hbase.ApplicationConfig.*;
import static com.hbase.utils.RandomUtil.*;
import static java.lang.Thread.sleep;

@Controller
@RequestMapping({"/charge"})
public class ChargeController {
    private static final Map<Integer, String> networkTypeMap = new HashMap();
    private static final Map<Integer, String> systemMap = new HashMap();
    @Autowired
    private UserService userService;
    protected static final Logger logger = Logger.getLogger(ChargeController.class);

    @RequestMapping({"/queryUser.do"})
    public String queryUser(HttpServletRequest request, Model model) throws Exception {

        int i=testMathRandom10000();

        new Test1();
        Integer rootApp=Integer.parseInt(ROOT_APP);
        Integer database1=Integer.parseInt(DATABASE1);
        Integer database2=0;
        if(!StringUtils.isEmptyOrNull(DATABASE2)){
            database2=Integer.parseInt(DATABASE2);
        }

        int max=rootApp;
        int min=database1+database2;
        if(max<min){

            //访问应用小于数据库
            max=min;
            min=rootApp;

            if(i%min<(max/2)){
                User user=this.userService.getUserById("admin");
                User user1=this.userService.getUserById("admin");
            }
        }else{

//            访问数据库小于访问应用
            if(i%max<min){
                User user=this.userService.getUserById("admin");
            }

        }

        i=testMathRandom1000();

        if(i%SLEEP_RATE1==0){
            if(i%4==1){
                sleep(i+1000);
            }else if(i%4==2){
                sleep(i+8000);
            }else if(i%4==3){
                sleep(i+3000);
            }
        }

        if(i% ERROR_RATE1 ==0){
            throw new NullPointerException();
        }
        return "User";
    }

    @RequestMapping({"/queryUserOwed.do"})
    public String queryUserOwed(HttpServletRequest request, Model model) throws Exception {

        int i=testMathRandom10000();

        new Test1();
        Integer rootApp=Integer.parseInt(ROOT_APP);
        Integer database1=Integer.parseInt(DATABASE1);
        Integer database2=0;
        if(!StringUtils.isEmptyOrNull(DATABASE2)){
            database2=Integer.parseInt(DATABASE2);
        }

        int max=rootApp;
        int min=database1+database2;
        if(max<min){

            //访问应用小于数据库
            max=min;
            min=rootApp;

            if(i%min<(max/2)){
                User user=this.userService.getUserById("admin");
                User user1=this.userService.getUserById("admin");
            }
        }else{

//            访问数据库小于访问应用
            if(i%max<min){
                User user=this.userService.getUserById("admin");
            }

        }

        i=testMathRandom1000();

        if(i%SLEEP_RATE2==0){
            if(i%4==1){
                sleep(i+1000);
            }else if(i%4==2){
                sleep(i+8000);
            }else if(i%4==3){
                sleep(i+3000);
            }
        }

        if(i% ERROR_RATE2 ==0){
            throw new NullPointerException();
        }
        return "User";
    }

    @RequestMapping({"/paySubmit.do"})
    public String paySubmit(HttpServletRequest request, Model model) throws Exception {

        int i=testMathRandom10000();

        new Test1();
        Integer rootApp=Integer.parseInt(ROOT_APP);
        Integer database1=Integer.parseInt(DATABASE1);
        Integer database2=0;
        if(!StringUtils.isEmptyOrNull(DATABASE2)){
            database2=Integer.parseInt(DATABASE2);
        }

        int max=rootApp;
        int min=database1+database2;
        if(max<min){

            //访问应用小于数据库
            max=min;
            min=rootApp;

            if(i%min<(max/2)){
                User user=this.userService.getUserById("admin");
                User user1=this.userService.getUserById("admin");
            }
        }else{

//            访问数据库小于访问应用
            if(i%max<min){
                User user=this.userService.getUserById("admin");
            }

        }

        i=testMathRandom1000();

        if(i%SLEEP_RATE3==0){
            if(i%4==1){
                sleep(i+1000);
            }else if(i%4==2){
                sleep(i+8000);
            }else if(i%4==3){
                sleep(i+3000);
            }
        }

        if(i% ERROR_RATE3 ==0){
            throw new NullPointerException();
        }
        return "User";
    }

    @RequestMapping({"/owedMakeUp.do"})
    public String arrearsReversal(HttpServletRequest request, Model model) throws Exception {

        int i=testMathRandom10000();

        new Test1();
        Integer rootApp=Integer.parseInt(ROOT_APP);
        Integer database1=Integer.parseInt(DATABASE1);
        Integer database2=0;
        if(!StringUtils.isEmptyOrNull(DATABASE2)){
            database2=Integer.parseInt(DATABASE2);
        }

        int max=rootApp;
        int min=database1+database2;
        if(max<min){

            //访问应用小于数据库
            max=min;
            min=rootApp;

            if(i%min<(max/2)){
                User user=this.userService.getUserById("admin");
                User user1=this.userService.getUserById("admin");
            }
        }else{

//            访问数据库小于访问应用
            if(i%max<min){
                User user=this.userService.getUserById("admin");
            }

        }

        i=testMathRandom1000();

        if(i%SLEEP_RATE4==0){
            if(i%4==1){
                sleep(i+1000);
            }else if(i%4==2){
                sleep(i+8000);
            }else if(i%4==3){
                sleep(i+3000);
            }
        }

        if(i% ERROR_RATE4 ==0){
            throw new NullPointerException();
        }
        return "User";
    }


    @RequestMapping({"/paySuccess.do"})
    public String paySuccess(HttpServletRequest request, Model model) throws Exception {

        int i=testMathRandom10000();

        new Test1();
        Integer rootApp=Integer.parseInt(ROOT_APP);
        Integer database1=Integer.parseInt(DATABASE1);
        Integer database2=0;
        if(!StringUtils.isEmptyOrNull(DATABASE2)){
            database2=Integer.parseInt(DATABASE2);
        }

        int max=rootApp;
        int min=database1+database2;
        if(max<min){

            //访问应用小于数据库
            max=min;
            min=rootApp;

            if(i%min<(max/2)){
                User user=this.userService.getUserById("admin");
                User user1=this.userService.getUserById("admin");
            }
        }else{

//            访问数据库小于访问应用
            if(i%max<min){
                User user=this.userService.getUserById("admin");
            }

        }

        i=testMathRandom1000();

        if(i%SLEEP_RATE5==0){
            if(i%4==1){
                sleep(i+1000);
            }else if(i%4==2){
                sleep(i+8000);
            }else if(i%4==3){
                sleep(i+3000);
            }
        }

        if(i% ERROR_RATE5 ==0){
            throw new NullPointerException();
        }
        return "User";
    }

}
